package everything.search;

import everything.WorldMap;

public class RTASearchAgent extends SearchAgent {
	private int _maxExpansions;
	private SearchAgentState _currState;

	public RTASearchAgent(String name, String color, int x, int y, WorldMap map,int maxExpansions) {
		super(name, color, x, y, map);
		_maxExpansions = maxExpansions;
		_type = "RTASearchAgent";

	}

	@Override
	public void initSentryLocation(int x, int y, String d) {
		// first run
		boolean[] tmp = new boolean[_map.getFlagList().size()]; // array of flags
		for (int i=0; i<tmp.length; i++){
			tmp[i] = true;
		}

		_currState = new SearchAgentState(_xLocation, _yLocation, null, x, y, d, !isGhost(), tmp);
	};

	public void makeMove() {

		RTASearch tmp = new RTASearch(_currState, _map, this, _maxExpansions);
		ASearchNode node = tmp.search(); // returns last node in search
		T = T + tmp.getT();

		// getting first move from top of tree
		while (node.getParent()!=null){
			if (node.getParent().getParent() == null) {
				_currState = node.getState();
				move(node.getMove());
				break;
			}
			node = node.getParent();
		}
	}
}

